//
//  MineTaskListController.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/30.
//  Copyright © 2016年 SpaceZ. All rights reserved.
//

#import "MineTaskListController.h"
#import "TaskDataCenter.h"
#import "MineTaskListView.h"
#import "MineTaskDetailController.h"

@interface MineTaskListController ()<MineTaskListViewDelegate>

@property (nonatomic, strong) TaskDataCenter *dataCenter;
@property (nonatomic, strong) MineTaskListView *listView;

@end

@implementation MineTaskListController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.baseTitle = @"我的任务";
    self.rightBtnTitle = @"返回";
    
    _dataCenter = [TaskDataCenter new];
    
    [self makeMineTaskListView];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)makeMineTaskListView
{
    _listView = [MineTaskListView new];
    _listView.delegate = self;
    [self.baseView addSubview:_listView];
    [_listView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.mas_equalTo(0);
    }];
}

- (void)headerRefresh:(NSInteger)page
{
    [self loadTaskListData:page];
}

- (void)footerLoadMore:(NSInteger)page
{
    [self loadTaskListData:page];
}

- (void)loadTaskListData:(NSInteger)page
{
    [_dataCenter fetchMineTaksListWithPage:page complation:^(id data, NSString *error) {
        
        if (error == nil) {
            [_listView loadMineTaskListData:(NSArray *)data];
        }else{
            [YJProgressHud showErrorHud:error];
        }
        
        
    }];
}

- (void)didSelectTask:(TaskModel *)taskModel index:(NSInteger)index
{
    MineTaskDetailController *detailController = [[MineTaskDetailController alloc] init];
    detailController.taskModel = taskModel;
    [self.navigationController pushViewController:detailController animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
